<template>
  <a-form-model
          ref="ruleForm"
          :model="form"
          :rules="rules"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
  >
    <a-form-model-item ref="name" label="商品名称" prop="goodsName">
      <a-input v-model="form.goodsName" />
    </a-form-model-item>

    <a-form-model-item >
      <span slot="label" class="ant-form-item-required">商品图片</span>
      <upload-image
              v-model="form.goodsPicture"
              @change="handleProductImageChange">
      </upload-image>
      <div class="desc">建议尺寸：1:1，支持jpg、png、jpeg格式</div>
    </a-form-model-item>

    <a-form-model-item label="库存设置" prop="stock">
        <a-input-number v-model="form.stock" :min="1" :max="5000">

        </a-input-number> 件
    </a-form-model-item>

    <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
      <a-button type="primary" @click="onSubmit">
        提交
      </a-button>

    </a-form-model-item>
  </a-form-model>
</template>
<script>
  // import ImageUploadList from '@/components/form/UploadImage'
  export default {
    components:{
      // ImageUploadList
    },
    data() {
      return {
        labelCol: { span: 4 },
        wrapperCol: { span: 8 },
        form: {
          goodsName: '',
          stock:1,
          goodsPicture:''
        },

        rules: {
          stock: [
            { required: true, message: '请输入库存', trigger: 'blur' },
          ],
          goodsName: [{ required: true, message: '请输入商品名称', trigger: 'change' }],


        },
      };
    },
    methods: {
      onSubmit() {
        console.log(this.form);
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            // alert('submit!');
            this.$post('goldenhome/gh/lottery_/admin/self/buildgoods/add',{
            //   参数
              goodsName:this.form.goodsName,
              stock:this.form.stock,
              goodsPicture:this.form.goodsPicture,
            //   givingType:3,
            }).then((res)=>{
              if (res && res.returnCode === 1000) {
                this.$message.success('添加成功')
                // 页面跳转一下
                this.$router.push({
                  name: 'MarketingSelfCreateGood',
                })
              }
            })
          } else {
            // console.log('error submit!!');
            return false;
          }
        });
      },
      handleProductImageChange(val){
        this.form.goodsPicture  =  val
        console.log(this.form.goodsPicture)
      },
    },
  };
</script>
